
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
country-list
Advanced tools
Maps ISO 3166-1-alpha-2 codes to English country names and vice versa.
The country-list npm package provides a simple way to get a list of countries and their corresponding ISO 3166-1 alpha-2 codes. It is useful for applications that need to display country names, validate country codes, or convert between country names and codes.
Get all countries
This feature allows you to retrieve a list of all countries along with their ISO 3166-1 alpha-2 codes.
const countries = require('country-list')().getData();
console.log(countries);
Get country name by code
This feature allows you to get the name of a country by providing its ISO 3166-1 alpha-2 code.
const countryList = require('country-list')();
const countryName = countryList.getName('US');
console.log(countryName);
Get country code by name
This feature allows you to get the ISO 3166-1 alpha-2 code of a country by providing its name.
const countryList = require('country-list')();
const countryCode = countryList.getCode('United States');
console.log(countryCode);
Add a custom country
This feature allows you to add a custom country to the list with a specified code and name.
const countryList = require('country-list')();
countryList.add({ code: 'XX', name: 'New Country' });
console.log(countryList.getData());
Remove a country
This feature allows you to remove a country from the list by providing its ISO 3166-1 alpha-2 code.
const countryList = require('country-list')();
countryList.remove('XX');
console.log(countryList.getData());
The i18n-iso-countries package provides a comprehensive list of countries with support for multiple languages. It allows you to get country names and codes, and also supports translations for country names in various languages. Compared to country-list, it offers more extensive localization features.
The country-data package provides detailed information about countries, including their names, codes, currencies, and regions. It offers more detailed data compared to country-list, making it suitable for applications that need more than just country names and codes.
The countries-list package provides a list of countries with their names, codes, and other related information. It is similar to country-list but includes additional data such as country calling codes and regions.
Maps ISO 3166-1-alpha-2 codes to English country names and vice versa.
Uses data from https://www.iso.org/iso-3166-country-codes.html
You can find version 1.* of country-list here.
const { getCode, getName } = require('country-list');
console.log(getName('IS')); // Iceland
console.log(getCode('Iceland')); // IS
console.log(getCode('Nowhere-to-be-found-land')); // undefined
And how to change the name of a country
const { overwrite, getName } = require('country-list');
overwrite([{
code: 'TW',
name: 'Taiwan'
}])
console.log(getName('TW')); // Taiwan
Usage:
const countryList = require('country-list');
All input is case-insensitive.
Expects an array of country objects containing code
and name
properties.
[{
code: 'TW',
name: 'Taiwan'
}]
Expects a two-digit country code.
Returns the name for that country.
If not found, it returns undefined
.
Expects the English country name.
Returns the code for that country.
If not found, it returns undefined
.
Returns an array of all country names.
Returns an array of all country codes.
Returns a key-value object of all countries using the name as key.
Returns a key-value object of all countries using the code as key.
Returns an array of all country information, in the same format as it gets imported.
npm install country-list
MIT
ISO makes the list of alpha-2 country codes available for internal use and non-commercial purposes free of charge.
FAQs
Maps ISO 3166-1-alpha-2 codes to English country names and vice versa.
The npm package country-list receives a total of 196,061 weekly downloads. As such, country-list popularity was classified as popular.
We found that country-list demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.